##### My (demuredemeanor) tmux config, a work in progress
# Uses tabstop=4; shiftwidth=4 tabs; foldmarker={{{,}}};
# https://notabug.org/demure/dotfiles/
# legacy repo http://github.com/demure/dotfiles
#
# Note to self: set=set-option; setw=set-window-option; setenv=set-environment;

### Main Settings ### {{{
## Fix glitch with underlined text in Terminal.app and hanging Prompt (iOS)
## From https://github.com/terlar/dotfiles/blob/master/tmux.conf
## Assume http://sourceforge.net/mailarchive/message.php?msg_id=30825085 is origin
set -ag terminal-overrides ",*:XT@"

new-session                     # tmux attach makes new, if not running
set -ga update-environment 'DISPLAY'    # Maybe fix DISPLAY?
set -g base-index 1             # Window numbering starts at 1
set -g pane-base-index 1        # Pane numbering starts at 1
setw -g automatic-rename on     # Auto set window title
setw -g aggressive-resize on    # Aggressive windows: For screen size, of diff connections, on diff windows
set -g default-terminal "screen-256color"
set -g history-limit 10000      # Scroll back history
set -g display-panes-time 4000  # Increase show pane time
set -g renumber-windows on      # Make windows auto renumber
set -g lock-command vlock       # Use vlock as console lock
### End Main Settings ### }}}

### Key Bindings ### {{{
unbind C-z                      # Unbind C-z so I don't suspend, and free for bind
#unbind C-b                      # Unbind C-b, so I can make C-z the prefix
set -g prefix C-z               # Change prefix key to C-z
bind-key C-z last-window        # Make <prefix>C-z go to last window
#unbind C-a
bind-key C-a send-prefix        # Make <prefix>C-a send C-z literally

## Join windows: <prefix> s, <prefix> j
bind-key j command-prompt -p "join pane from:"  "join-pane -s '%%'"
bind-key s command-prompt -p "send pane to:"  "join-pane -t '%%'"

## URL grab: <prefix> u
bind-key u capture-pane \; save-buffer /tmp/tmux-buffer \; new-window -n "urlview" '$SHELL -c "urlview < /tmp/tmux-buffer"'

## Reload tmux.conf: <prefix> R
bind R source-file ~/.tmux.conf \; display-message "Config reloaded..."

## Lock screen
bind-key -T prefix X confirm-before -p "lock tmux? (y/n)" lock-session

    ### Better Bindings for Splitting ### {{{
    bind h split-window -h
    bind v split-window -v
    ### End Splitting Bindings ### }}}

    ## Mouse
    set -g mouse on

    ### vi Mode for Scroll Back ### {{{
    setw -g mode-keys vi
    #unbind [
    bind Escape copy-mode
    unbind p
    bind p paste-buffer
    bind-key -t vi-copy 'v' begin-selection
    bind-key -t vi-copy 'y' copy-selection
    bind-key -t vi-copy Escape cancel
    bind-key -t vi-copy 'Y' copy-end-of-line
    bind-key -t vi-copy 'V' select-line
    ### End vi Mode ### }}}

    ### Move Window Numbers ### {{{
    ## <prefix> Shift left/right
    # Inspired by https://superuser.com/questions/343572/how-do-i-reorder-tmux-windows
    bind-key S-Left swap-window -t -1
    bind-key S-Right swap-window -t +1
    ### End Window Numbers ### }}}
### End Key Bindings ### }}}

### Theming Settings ### {{{
## Terminal emulator window title
set -g set-titles on
set -g set-titles-string '#S:#I.#P #W'

## Notifying if other windows has activities
setw -g monitor-activity on
set -g visual-activity on

## Clock
setw -g clock-mode-colour green
setw -g clock-mode-style 24

## Inactive windows
setw -g window-status-format '#[fg=cyan,dim]#I#[fg=blue]:#[default]#W#[fg=grey,dim]#F'

    ### Status Bar ### {{{
    set -g status-bg black
    set -g status-fg white
    set -g status-interval 1
    set -g status-left '#[fg=green]#H#[default]'
    set -g status-right '#[fg=cyan,bold]%Y-%m-%d %H:%M#[default]'

        ### Bar Current ### {{{
        ## Highlighting the active window in status bar
        #setw -g window-status-current-bg blue
        setw -g window-status-current-format '#[bg=blue,fg=cyan,bold]#I#[bg=blue,fg=cyan]:#[fg=white]#W#[fg=dim]#F'

        ### End Current ### }}}

        ### Bar Last ### {{{
        #setw -g window-status-last-attr attributes
        #setw -g window-status-last-bg color
        #setw -g window-status-last-fg color
        ### End Last ### }}}

    ### End Status Bar ### }}}

    ### Message/Message Command ### {{{
    set -g message-attr bright
    set -g message-bg cyan
    set -g message-fg white
    set -g message-command-attr bright
    set -g message-command-bg cyan
    set -g message-command-fg white
    ### End Message ### }}}

    ### Pane Colors ### {{{
    set -g pane-border-fg cyan
    set -g pane-active-border-fg cyan
    ### End Pane Colors ### }}}
### End Theming Settings ### }}}
